package com.cloudkinto.service.consumer;

import com.alibaba.fastjson.JSONObject;
import com.cloudkinto.common.RabbitQueueConstant;
import com.cloudkinto.service.consumer.vo.rakuten.ItemUpdateConsumerReq;
import com.cloudkinto.service.platform.shopList.PlatformOrderSuperDeliverySyncService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class PlatformOrderSuperDeliverConsumer {
    private final PlatformOrderSuperDeliverySyncService platformOrderSuperDeliverySyncService;

    /**
     * 同步平台商品
     * @param msg
     */
    @RabbitListener(queuesToDeclare = @Queue(RabbitQueueConstant.GetPlatformProduct_SuperDelivery))
    public void getItem(String msg) {
        ItemUpdateConsumerReq req = JSONObject.parseObject(msg, ItemUpdateConsumerReq.class);
        try {
            String string = platformOrderSuperDeliverySyncService.productSetSearch(req.getStoreDo());
            if (StringUtils.isNotBlank(string)) {
                log.error("乐天同步平台商品失败：" + string);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
